<template>
  <div class="tenantMenu_main main_container add_container">
    <div v-loading="loading" class="main_main">
      <div class="SearchBar_main main_main_search">
        <div class="main_main_search_item">
          <div class="formItem_header">
            <div class="formItem_header_operate">
              <!-- <a class="formItem_header_operate_items" @click="add">
                <svg-icon icon-class="新增" />
                <div class="item_name">新增</div>
              </a> -->
            </div>
          </div>
        </div>
        <div class="main_main_search_item">
          <el-input v-model="searchValue" style="width:240px;margin-right:10px" placeholder="请输入工艺要求编码或工序" clearable @keyup.enter.native="getList" @clear="getList" />
          <el-button style="background:#387bfc;width:30px;" icon="el-icon-search" @click.stop="getList" />
        </div>
      </div>
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          :row-class-name="tableRowClass"
          :height="tableHeight"

          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          @sort-change="(column)=>{sortChange(column, this)}"
          @row-click="onSubmit"
        >
          <Column v-for="(column,index) in defaultTableColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { getEngineeringRequirementsMaterialListByMaterialId } from '@/api/outsourceManage/outsourceOrder'
import AddOrUpdate from './addOrUpdate' // 新增或编辑页面

export default {
  name: 'Index',
  props: {
    layerid: {},
    materialId: {},
    id: {}
  },
  data() {
    return {
      searchValue: '',
      loading: true,
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc'
      },
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'engineeringRequirementCode', label: '工艺要求编码' },
        { prop: 'engineeringRequirementVersionCode', label: '工艺版本号' },
        { prop: 'engineeringProcessName', label: '工序' },
        { prop: 'productBySelfName', label: '标记工序' }
      ],
      selectionsRow: {}
    }
  },
  mounted() {
    this.getList()
    this.$nextTick(() => {
      this.tableHeight = this.$refs.table_container.offsetHeight
    })
  },
  methods: {
    getList() {
      getEngineeringRequirementsMaterialListByMaterialId({ materialId: this.materialId, searchValue: this.searchValue, status: '1' }).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.loading = false
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
        })
      })
    },
    tableRowClass({ row }) {
      if (row.id == this.id) {
        return 'selectedRow'
      } else {
        return ''
      }
    },
    // 单选
    singleElection(row) {
      this.selectionsRow = row
      this.templateSelection = row.id
    },
    add() {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
          }// props
        },
        area: ['440px', '500px'],
        title: '新增库位', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    cellClassName(data) {
      if (data.column.property == 'operate') {
        if (data.rowIndex % 2 == 0) {
          // 单数行
          return 'fixed one'
        } else {
          // 双数行
          return 'fixed two'
        }
      }
    },
    cancel() {
      this.$layer.close(this.layerid)// 关闭弹框
    },
    onSubmit(row) {
      this.$parent.chooseEngineeringRequirementCallBack(row)
      this.$layer.close(this.layerid)// 关闭弹框
    }
  }
}
</script>

<style lang="less" scoped>
/deep/ .el-table .selectedRow {
  background: #387bfc;
  color: #ffffff;
}
/deep/ .el-table--enable-row-hover .el-table__body tr:hover > td {
  background-color: rgba(56, 123, 252, 0.5) !important;
  color: #ffffff;
}
.main_bottoms{
  width: 100%;
  height: 50px;
  background-color: white;
  padding: 0px 30px;
  display: flex;justify-content:space-between;align-items: center;
}
.formItem_header_operate_items{
  height: 30px;
  display: flex;justify-content: center;align-items: center;
  padding: 0px 10px;font-size: 16px;border-radius: 4px;
  color: rgba(56, 123, 252, 1);background-color: rgba(235, 242, 255, 1);
  .item_name{
    font-size: 14px;padding-left: 10px;
  }
}
.formItem_header_operate_items:hover{
  background-color: rgba(235, 242, 255, 0.5);
}
.main_bottom{
  padding-right: 20px !important;
}
.main_search_item{
  padding-right: 20px !important;
}
.main_main_search_item{
  width: unset !important;
  padding-left: 20px !important;
}
.main_main{
  margin: 0 !important;
  padding-top:0 !important ;
}
</style>
